package com.hzhjhh.view.cashierView.dto;

import java.math.BigDecimal;
import java.util.Objects;

import com.hzhjhh.entity.Merchandise;
import com.hzhjhh.entity.base.BaseEntity;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 商品信息展示对象
 */
@Data
@Accessors(chain = true)
public class MerchandiseShowVO extends BaseEntity {
	
	/**
	 *商品 编码
	 */
	private String code;
	
	/**
	 * 商品名称
	 */
	private String name;
	
	/**
	 * 规格
	 */
	private String spec;
	
	/**
	 * 单位
	 */
	private String units;
	
	/**
	 * 数量
	 */
	private String number;
	
	/**
	 * 售价
	 */
	private String salePrice;
	
	/**
	 * 折扣
	 */
	private String discount;

    /**
     * 金额
     */
    private String amt;

    public static MerchandiseShowVO getFromEntity(Merchandise merchandise, int number, int discount) {
		MerchandiseShowVO vo = new MerchandiseShowVO();
		if (Objects.isNull(merchandise)) {
			return vo;
		}
		BigDecimal salePrice = merchandise.getMerchandiseRetailPrice();
		vo.setCode(merchandise.getMerchandiseTreatyCode());
		vo.setName(merchandise.getMerchandiseName());
		vo.setSpec(merchandise.getMerchandiseSpec());
		vo.setUnits(merchandise.getMerchandiseUnits());
		vo.setNumber(String.valueOf(number));
		vo.setSalePrice(salePrice.toPlainString());
		vo.setDiscount(String.valueOf(discount));
		vo.setAmt(
			BigDecimal.valueOf(number)
				.multiply(salePrice)
				.multiply(BigDecimal.valueOf(discount))
				.divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP)
				.toPlainString()
		);
		return vo;
	}
}